package com.bigflexlib.x.mx.core
{
	import flash.utils.Dictionary;
	
	import mx.core.ClassFactory;

	/**
	 * @author abucchi
	 * 
	 */
	public class SingletonClassFactory
	{
		private var cache:Dictionary = new Dictionary( );
		
		public function getInstance( clazzOrInstance:Object, instantiationCallback:Function=null ):* {
			if ( ! ( clazzOrInstance is Class ) )
				return clazzOrInstance;
			var k:Class = clazzOrInstance as Class;
			if ( cache[ k ] )
				return cache[ k ];	
			var i:* = (new ClassFactory(k)).newInstance( );
			if ( instantiationCallback )
				instantiationCallback( i );
			cache[ k ] = i;
			return i; 	
		}		
	}
}